<template>
    <h3>购买理财项目</h3>

    <table border="1">
        <tr>
            <td>登录用户名</td>
            <td>
                <input type="text" v-model="info.SUName"></input>
            </td>
        </tr>
        <tr>
            <td>理财项目名称</td>
            <td>
                <input type="text" v-model="info.SName"></input>
            </td>
        </tr>
        <tr>
            <td>理财收益</td>
            <td>
                <input type="text" v-model="info.SPrice"></input>
            </td>
        </tr>
        <tr>
            <td>购买金额</td>
            <td>
                <input type="text" v-model="info.BuyPrice"></input>
            </td>
        </tr>
        <tr>
           <td colspan="2" @click="Add">添加</td>
        </tr>
    </table>
</template>

<script setup lang="ts">
import { ref,onMounted } from 'vue'
import axios from 'axios';
import { useRoute } from 'vue-router';
const route = useRoute();
const info = ref({
    SUName: "",
    SName: "",
    SPrice: "",
    BuyPrice:""
})

onMounted(()=>{
    FanTian();
})

const FanTian = () => {
   

    axios.get("http://localhost:8177/api/Money/FanTian",{
        params:{
            Sid:route.params.Sid,
            SUName: info.value.SUName,
            SName: info.value.SName,
            SPrice: info.value.SPrice,
        }
    })
    .then((res) => {
       info.value = res.data;
    })
}

const Add=()=>{
    if(info.value.BuyPrice==""){
        
        alert("购买金额不能为空")
        return;
    }
     //判断理财收益
     if(info.value.BuyPrice<info.value.SPrice){
        alert("购买金额不能小于理财收益")
    }else{
        alert("购买成功")
    }
   
}

</script>